import type { OrderDetailType, OrderLogisticsRes } from "@/types/detail";
import { http } from "@/untils/request";

/**
 * 获取订单详情
 * @param id 
 * @returns 
 */
export const getOrderDetailAPI = (id: string) => {
    return http<OrderDetailType>({
        url: `/member/order/${id}`,
        method: 'GET'
    })
}

/**
 * 模拟支付-内测版
 * @param id 
 * @returns 
 */
export const payOrderAPI = (data: { orderId: string }) => {
    return http({
        url: '/pay/mock',
        method: 'GET',
        data
    })
}

// 获取微信支付参数
// GET
// /pay/wxPay/miniPay

export const PayWxPayMiniPayAPI = (data: { orderId: string }) => {
    return http<WechatMiniprogram.RequestCommonPaymentOption>({
        url: '/pay/wxPay/miniPay',
        method: 'GET',
        data
    })
}

/**
 * 模拟发货-内测版
 * @param id 
 * @returns 
 */
export const memberOrderPayAPI = (id: string) => {
    return http({
        url: `/member/order/consignment/${id}`,
        method: 'GET'
    })
}

/**
 * 确认收货
 * @description 仅在订单状态为待收货时，可确认收货。
 * @param id 订单id
 */
export const putMemberOrderReceiptByIdAPI = (id: string) => {
    return http<OrderDetailType>({
        method: 'PUT',
        url: `/member/order/${id}/receipt`,
    })
}

/**
 * 获取订单物流
 * @param id 订单编号
 */
export const getMemeberOrderLogisticsAPI = (id: string) => {
    return http<OrderLogisticsRes>({
        url: `/member/order/${id}/logistics`,
        method: 'GET'
    })
}

/**
 * 删除订单
 * @param data 
 * @returns 
 */
export const deleteOrderAPI = (data: { ids: string[] }) => {
    return http({
        url: '/member/order',
        method: 'DELETE',
        data
    })
}

/**
 * 取消订单
 * @param id 订单id
 * @param data 取消理由
 * @returns 
 */
export const cancelOrderAPI = (id: string, data: { cancelReason: string }) => {
    return http<OrderDetailType>({
        url: `/member/order/${id}/cancel`,
        method: 'PUT',
        data
    })
}